var myiscroll=null;
$(function(){
/*
	$(".top-bar-cont span:first-child").on("tap",function(){  //后退功能
		location.href="../index.html";
	});
	*/
	leftmenu("#leftmenu","#wrap");
	
	var today = new Date();
	var month = today.getMonth()+1;
	var year = today.getFullYear();
	var lastday = new Date(year,month,0);
	if(month<10)
		month = "0"+month;
	var yearMonth = year+"/"+month;
	var todayt = today.getFullYear() + ' 年    <span class="m-118" >  '+month+'   月 </span>';
	$("#myH2").text('');
	$("#myH2").html(todayt);
	ycquery(yearMonth);
	$("#errorBtncancel").on("tap",function(){
		$("#errorMask").hide();
	});
		$('#bdate').scroller('destroy').scroller({
			preset: 'date',
			dateFormat: 'yymm',
			dateOrder: 'yymm',
			minDate: new Date(2002, 3, 10, 9, 22),
			maxDate: new Date(2030, 7, 30, 15, 44),
			theme: 'ios',
			mode: 'scroller',
			lang: 'zh',
			display: 'bottom',
			animate: 'slideup'
		});
});
    
function ycquery(yearMonth){
	$("#ullist").empty();
	$(".footer-fixed").show();
	$("#loadingText").show();
	iscroll();
	$.ajax({
		type: "post",
		url: mpsurl+"/mobile/checkin/queryExceptionChenkinList.do",
		dataType: "json",
		data:{yearMonth:yearMonth},
		success: function (data) {
			$("#ullist").empty();
			if(data.resultCode=="500600"){
				if(data.value.length==0){
					$("#norecord").show();
					$(".footer-fixed").show();
					$("#hasrecord").hide();
					$("#loadingText").hide();
					iscroll();
				}else{
					$("#loadingText").hide();
					$("#norecord").hide();
					$("#hasrecord").show();
					analysisData(data,"#ullist");
				}
				
			}else{
				$("#loadingText").hide();
				iscroll();
				checkLogin(data.resultCode,"/mobile/mywork/ycwork.html",data.resultMessage);
			}
		},
		error: function (XMLHttpRequest, textStatus, errorThrown) {
			$("#ullist").empty();
			$("#loadingText").hide();
			iscroll();
			//errorMask("网络连接不可用");
			setPromptForInput("网络连接不可用");
		}
	});
}
function analysisData(data,id){
	$(id).html('');
	var obj = data.value;
	for(var i=0;i<obj.length;i++){
		var exceptionDate = obj[i].exceptionDate;
		var ym = exceptionDate.substr(0,7);
		var da = exceptionDate.substr(8,2);
		var qjdate = ym+"-"+da;
		var descr=obj[i].descr;
		var totalTime = obj[i].totalTime;
		var qjTime = obj[i].totalTime;
		if(totalTime.substr(0,1)==".")
			totalTime = "0"+totalTime +"小时";
		else if(totalTime==0)
			totalTime ="";
		else
			totalTime = totalTime+"小时";
		if(descr=="中间外出超时")
			descr="外出超时";
		var li=$("<li>"
			+"<div class=\"detail-record-list-cont\">"
			+"<span class=\"css-icon\"></span>"
			+"<div class=\"list-cont\" onclick=\"qjwork('"+qjdate+"&qjTime="+qjTime+"&descr="+descr+"')\"><div class=\"detail-record-time\">"
			+"<p class=\"time-dd\">"+da+"</p><p class=\"time-yymm\">"+ym+"</p></div>"
			+"<div class=\"detail-record-cont\">"
			+"<div class=\"detail-record-cause\">"
			+"<div class=\"fn-right m-l18 fn-c-ccc fn28\">去请假</div>"
			+descr + totalTime
			+"</div>"
			+"</div>"
			+"</div>"
			+"</div>"
			+"<figure class=\"smallicon-sprite state-icon\"></figure>"
			+"</li>");
		$(id).append(li);
	}
	$(".footer-fixed").show();
	iscroll();
}
function qjwork(qjdate){
	//location.href="sqwork.html?qjdate="+qjdate;
	var param="qjdate="+qjdate;
	gotoLocation("/mobile/mywork/sqwork.html",param);
}
function gotoSQwork(){
	//location.href="sqwork.html";
	gotoLocation("/mobile/mywork/sqwork.html","");
}
function gotoQJwork(){
	//location.href="qjwork.html";
	gotoLocation("/mobile/mywork/qjwork.html","");
}
function show(){
	$('#bdate').scroller('show');
	$(".dwo").css("background-color","#000");
    $(".dwo").css("opacity",".5");
    $(".dwo").css("z-index","1000");
}
$(document).on("tap", function(){
    $(".dw dwbg").on("tap",function(){
    	return;
    })
    $(".dwo").on("tap",function(){
    	$("#promptBox").remove("slow");	
    })
    $(".dwbw dwb-c").on("tap",function(){
    	$("#promptBox").remove("slow");	
    })
    $(".dwbw dwb-s").on("tap",function(){
    	$("#promptBox").remove("slow");	
    })
});
function change(){
	var da =  $("#bdate").val();
	var yy = da.substring(0,4);
	var mm = da.substring(4,da.length);
	var yearMonth =yy+"/"+mm;
	var te = yy + ' 年    <span class="m-118" >  '+mm+'   月 </span>';
	$("#myH2").text('');
	$("#myH2").html(te);
	ycquery(yearMonth);
}
function iscroll(){
	var wh = $(window).height()-272; 
	if(myiscroll instanceof iScroll)
		myiscroll.destroy();
	$("#iscrollContent").css("height",wh+"px");
	myiscroll = new iScroll("iscrollContent",{bounce:false});
}